<template>
  <view class="container">
    <view class="top-bg">
      <image
        class="img1"
        mode="aspectFit"
        src="../static/images/download/img1.png"
      />
    </view>
    <view class="bottom-bg">
      <view class="qc-info">
        <view class="logo-com">
          <image class="logo" src="../static/images/download/logo.png" />
          <view class="title">企橙车务通</view>
        </view>
        <view class="qc-code">
          <image
            class="download-code"
            style="width: 139rpx; height: 139rpx"
            :src="codeImgSrc"
          />
        </view>
        <view class="download-btn" @click="onGoToAndroid"
          >下载安卓版企橙车务通APP</view
        >
        <view class="version">版本号：{{ version }}</view>
      </view>
    </view>
  </view>
</template>

<script>
import { http } from "@/utils/http";
const env = process.env.NODE_ENV;
const codeImgSrcConfig = {
  development: "../static/images/download/env-development.png",
  production: "../static/images/download/env-production.png",
};
const sys = uni.getSystemInfoSync();

export default {
  data() {
    return {
      sys,
      backgroundSize: "",
      codeImgSrc: codeImgSrcConfig[env],
      version: "",
    };
  },
  mounted() {
    http({
      method: "POST",
      url: "/wwwAppVersion/getNewVersion",
      data: {
        clientType: 1,
      },
      header: { needLoading: false },
    })
      .then((res) => {
        this.version = res.result.version;
      })
      .catch((error) => {
        uni.showToast({
          icon: "none",
          title: error.message,
        });
      });
  },

  methods: {
    onGoToAndroid() {
      const ua = navigator.userAgent.toLowerCase();
      const isWeixin = ua.indexOf("micromessenger") != -1;
      if (isWeixin) {
        uni.showToast({
          icon: "none",
          duration: 2000,
          title: "微信内置浏览器无法安装，请用外部浏览器打开。",
        });
      } else {
        const downloadUrl = {
          development:
            "https://mc-imagehost.oss-cn-beijing.aliyuncs.com/qc_app/test/qccwAndroidAPP.apk",
          production:
            "https://mc-imagehost.oss-cn-beijing.aliyuncs.com/qc_app/online/qccwAndroidAPP.apk",
        };
        const url = `${downloadUrl[env]}?timeStamp=${new Date().getTime()}`;
        window.location.href = url;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
/* 高分辨率 高度 */
$topHeight: 65vh;
$bottomHeight: 45vh;

/* 低高分辨率 高度 */
$topMobileHeight: 70vh;
$bottomMobileHeight: 37vh;

.flex {
  display: flex;
  justify-content: center;
  flex-direction: column;
}
.container {
  width: 100%;
  height: 100%;
  border-radius: 0rpx 0rpx 0rpx 0rpx;
  z-index: 1;
  display: flex;
  justify-content: center;
  .top-bg {
    background: linear-gradient(180deg, #ffffff 0%, #e2eaf9 100%);
    width: 100%;
    z-index: 1;
    height: $topHeight;
    position: absolute;
    top: 0;
    .img1 {
      display: inline-block;
      position: absolute;
      width: 80%;
      height: 70%;
      bottom: 20%;
      left: 50%;
      transform: translateX(-50%);
    }
    @media (max-width: 900px) {
      height: $topMobileHeight;
      .img1 {
        bottom: 16%;
      }
    }
  }
  .bottom-bg {
    width: 100%;
    z-index: 2;
    height: $bottomHeight;
    position: absolute;
    bottom: 0;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    // 背景图
    @media (max-width: 900px) {
      background-image: url("../static/images/download/mobile-bg.png");
      height: $bottomMobileHeight;
    }
    @media (min-width: 900px) {
      background-image: url("../static/images/download/pc-bg.png");
    }
    .qc-info {
      display: flex;
      flex-direction: column;
      align-items: center;
      text-align: center;
      justify-content: space-between;
      margin-top: 6vh;
      height: calc($bottomHeight - 6vh);
      padding-bottom: 40rpx;
      @media (max-width: 900px) {
        margin-top: -0.5vh;
        height: calc($bottomMobileHeight - -0.5vh);
      }
      .logo-com {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 200rpx;
        .logo {
          display: inline-block;
          width: 111rpx;
          height: 111rpx;
          margin-bottom: 17rpx;
        }
        .title {
          width: 139rpx;
          font-family: PingFang SC, PingFang SC;
          font-weight: 600;
          font-size: 22rpx;
          color: #ffffff;
          line-height: 31rpx;
          text-align: center;
          font-style: normal;
          text-transform: none;
        }
      }
    }
    .qc-code {
      display: inline-block;
    }
    .download-btn {
      width: 411rpx;
      height: 67rpx;
      line-height: 67rpx;
      border-radius: 863rpx 863rpx 863rpx 863rpx;
      background: #ffffff;
      border: 3rpx solid #ffffff;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 25rpx;
      color: #015aff;
      text-align: center;
      font-style: normal;
      text-transform: none;
    }
    .version {
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 19rpx;
      color: #ffffff;
      line-height: 31rpx;
      text-align: center;
      font-style: normal;
      text-transform: none;
    }
  }
}
</style>
